package com.demo.datastructure.reorder.insertionSort;

import com.demo.datastructure.reorder.Example;

/**
 * @author ljr
 * @version 1.0
 * @description: 插入排序
 * @date 2021/9/23 21:38
 */
public class SimpleInsertSort5 implements Example {

    @Override
    public void sort(Comparable[] a) {
        for(int i = 0, j = i; i < a.length; j = ++i){
            Comparable value = a[i+1];
            while(less(value, a[j])){
                a[j+1] = a[j];
                if(j-- == 0){
                    break;
                }
            }
            a[j+1] = value;
        }
    }
}
